﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BIS.Portal.Core.Base;
using BIS.Portal.Core.Global;
using BIS.Utility.Converter;

namespace BIS.Portal.Modules.CMS
{
    public partial class CmsSimpleSearch : ControlBase
    {
        #region Load Control settings
        public string PageAlias
        {
            get { return GetControlSetting<string>(ModuleSettingNames.CmsSimpleSearch.ddlPageAlias, PortalContext.LanguageAlias); }
        }
        #endregion
        protected void Page_Load(object sender, EventArgs e)
        {
            Search.Text = GetLanguageValue("SearchButton");
        }

        protected void Search_Click(object sender, EventArgs e)
        {
            string iCateId=Functions.GetString(Request[ModuleQueryStringKey.CategoryId]);
            DateTime tu_ngay = Convert.ToDateTime("01/02/1888");
            DateTime den_ngay = Convert.ToDateTime("01/02/4999");
            #region Url Tìm kiếm 
            string urlAdvanceSearchKeyword = WebHelpers.GetLink(ModuleQueryStringKey.UrlAdvancedSearchNoKeyword,
                                                               PageAlias,
                                                               new string[]
                                                                    {
                                                                        ModuleQueryStringKey.cms_from_date,
                                                                        ModuleQueryStringKey.cms_to_date,
                                                                        ModuleQueryStringKey.CategoryId
                                                                    },
                                                               new string[]
                                                                    {
                                                                        tu_ngay.ToString("yyyy-MM-dd"),
                                                                        den_ngay.ToString("yyyy-MM-dd"),
                                                                        iCateId
                                                                    });
            if (Keyword.Text != "")
            {
                urlAdvanceSearchKeyword = WebHelpers.GetLink(ModuleQueryStringKey.UrlAdvancedSearchWithKeyword,
                                                                PageAlias,
                                                                new string[]
                                                                    {
                                                                        ModuleQueryStringKey.cms_keyword,
                                                                        ModuleQueryStringKey.cms_from_date,
                                                                        ModuleQueryStringKey.cms_to_date,
                                                                        ModuleQueryStringKey.CategoryId
                                                                    },
                                                                new string[]
                                                                    {
                                                                        Keyword.Text,
                                                                        tu_ngay.ToString("yyyy-MM-dd"),
                                                                        den_ngay.ToString("yyyy-MM-dd"),
                                                                        iCateId
                                                                    });
            }
            #endregion
            Response.Redirect(urlAdvanceSearchKeyword);
        }
    }
}